package com.marktotop.controller.system;


import com.marktotop.entity.system.Log;
import com.marktotop.response.ResultBean;
import com.marktotop.service.ILogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 操作日志表 前端控制器
 * </p>
 *
 * @author MarkToTop
 * @since 2021-07-12
 */
@Api(tags = "系统模块-操作日志接口")
@RestController
@RequestMapping("/system/log")
public class LogController {

    @Autowired
    private ILogService logService;

    /**
     * 日志列表
     *
     * @return
     */
    @ApiOperation(value = "日志列表", notes = "系统日志列表，模糊查询")
    @RequestMapping(value = "/findLogList",method = RequestMethod.GET)
    public ResultBean findLogList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                  @RequestParam(value = "pageSize") Integer pageSize,
                                  Log log) {
        return logService.findLogList(pageNum, pageSize, log);
    }


    /**
     * 删除日志
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "删除日志",notes = "删除单条日志")
    @RequiresPermissions({"log:delete"})
    @RequestMapping(value = "/delete/{id}",method = RequestMethod.DELETE)
    public ResultBean delete(@PathVariable Long id) {
        if (!logService.removeById(id)){
            return ResultBean.error().message("删除系统日志失败!");
        }
        return ResultBean.ok().message("删除系统日志成功!");
    }


    /**
     * 批量删除日志
     *
     * @param ids
     * @return
     */
    @ApiOperation(value = "批量删除",notes = "批量删除多条日志")
    @RequiresPermissions({"log:batchDelete"})
    @RequestMapping(value = "/batchDelete/",method = RequestMethod.DELETE)
    public ResultBean batchDelete(Integer[] ids) {
        if (logService.removeByIds(Arrays.asList(ids))){
            return ResultBean.ok().message("批量删除操作日志信息成功！");
        }
        return ResultBean.error().message("批量删除操作日志信息失败！");
    }


}
